import { _decorator, Camera, Component, find, Node, UITransform, Vec3 } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('PlaneLabel')
export class PlaneLabel extends Component {
    private uiCamera:Camera = null;
    private parentTransform:UITransform = null;
    start() {
        this.uiCamera = find('Canvas/Camera').getComponent(Camera);
        this.parentTransform = this.node.parent.getComponent(UITransform)
    }

    update(deltaTime: number) {
        
    }

    public showAt(scenePos:Vec3):void{
        var wPos = this.uiCamera.screenToWorld(scenePos)
        var pos = this.parentTransform.convertToNodeSpaceAR(wPos)
        this.node.setPosition(pos)
    }
}


